package com.hyper_yang.javase.reflection_annotation.load;

import org.junit.jupiter.api.Test;
/*
获取类对象: (只要类加载了，就会产生类对象)
    1、类名.class
    2、对象名.getClass()
    3、Class.forName("全类名")
    4、类加载器.loadClass("全类名")  了解即可
 */
public class ClassGetTest {
    @Test
    public void test1() {
        // todo: 类名.class
        Class<Student> studentClass = Student.class;
        System.out.println(Student.class);
    }

    @Test
    public void test2() {
        // todo: 对象名.getClass()
        Student student = new Student(); // 会对类初始化
        Class<? extends Student> aClass = student.getClass();
        System.out.println(aClass);
    }

    @Test
    public void test3() throws ClassNotFoundException {
        // todo: 主动类加载
        Class<?> studentClass = Class.forName("com.hyper_yang.reflection_annotation.load.Student");
        System.out.println(studentClass);
    }

    @Test
    public void test4() throws ClassNotFoundException {
        // todo: 类加载器.loadClass("全类名")  获取一个类的类加载器，加载另一个类
        Class<Person> personClass = Person.class;
        ClassLoader classLoader = personClass.getClassLoader();
        Class<?> aClass = classLoader.loadClass("com.hyper_yang.reflection_annotation.load.Student");
        System.out.println(aClass);
    }
}